import 'package:flutter/widgets.dart';

class CollectionCoreTranslation {
  static final delegate = _CollectionCoreTranslationDelegate();

  static CollectionCoreTranslation of(BuildContext context) {
    return Localizations.of(context, CollectionCoreTranslation);
  }

  late String _languageCode;

  Future<void> load(Locale locale) async {
    _languageCode = locale.languageCode;
  }

  String _resolve(Map<String, String> translations) {
    return translations[_languageCode]!;
  }

  String get collectionTitleTextFieldPlaceholder {
    return _resolve(const {
      'ru': 'Название коллекции',
      'en': 'Collection name',
    });
  }

  String get collectionFolderTitleTextFieldPlaceholder {
    return _resolve(const {
      'ru': 'Название папки',
      'en': 'Folder name',
    });
  }

  String get collectionTitleEnteringInstruction {
    return _resolve(const {
      'ru': 'Введи название',
      'en': 'Enter name',
    });
  }

  String get collectionFolderTitleEnteringInstruction {
    return _resolve(const {
      'ru': 'Введи название',
      'en': 'Enter name',
    });
  }

  String get allLexicalItemSelectionActionTileTitle {
    return _resolve(const {
      'ru': 'Выбрать все слова',
      'en': 'Select all words',
    });
  }

  String get allLexicalItemDeselectionActionTileTitle {
    return _resolve(const {
      'ru': 'Отменить выбор всех слов',
      'en': 'Deselect all words',
    });
  }
}

class _CollectionCoreTranslationDelegate extends LocalizationsDelegate<CollectionCoreTranslation> {
  @override
  bool isSupported(Locale locale) => const ['ru', 'en'].contains(locale.languageCode);

  @override
  bool shouldReload(LocalizationsDelegate<CollectionCoreTranslation> old) => false;

  @override
  Future<CollectionCoreTranslation> load(Locale locale) async {
    final translation = CollectionCoreTranslation();
    await translation.load(locale);
    return translation;
  }
}
